package com.meituan.service.impl;

import com.meituan.dao.CommentMapper;
import com.meituan.dao.CommentRepository;
import com.meituan.pojo.entity.Comment;
import com.meituan.pojo.req.CommentReq;
import com.meituan.pojo.resp.BaseResp;
import com.meituan.pojo.resp.CommentResp;
import com.meituan.service.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    CommentRepository commentRepository;
    @Override
    public BaseResp findBySidAndGid(Integer sid, Integer gid) {



        List<CommentResp> all = commentMapper.findAll(sid, gid);

        if (all==null){
            return new BaseResp().ERROR();
        }

        return new BaseResp(1,"success",all);
    }

    @Override
    public BaseResp insert(CommentReq commentReq) {
        BaseResp baseResp= new BaseResp();
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentReq, comment);
        Comment save = commentRepository.save(comment);
        if (save!=null){
            return baseResp.SUCCESS();
        }
        return baseResp.ERROR();
    }
}
